package net.miranti;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Main {
	static final EntityManagerFactory emf = 
		Persistence.createEntityManagerFactory("default");
	
	public static void main(String[] args) {
		EntityManager em = emf.createEntityManager();
		
		em.getTransaction().begin();
		
		User user = new User();
		user.setName("Vitor");
		user.setLogin("vitor.oa");
		user = em.merge(user);
		em.createQuery("update User set password = MD5('abc')").executeUpdate();
		
		Role role = new Role(user, "ADMIN");
		role = em.merge(role);
		em.getTransaction().commit();

		em.close();
	}
}
